package com.heima.search.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heima.model.search.pojo.SearchHistory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SearchHistoryMapper extends BaseMapper<SearchHistory> {

    /**
     * 查询用户的搜索历史，按时间倒序排列，最多10条
     * @param userId 用户ID
     * @return 搜索历史列表
     */
    @Select("SELECT * FROM search_history WHERE user_id = #{userId} ORDER BY created_time DESC LIMIT 10")
    List<SearchHistory> selectByUserIdOrderByCreatedTimeDesc(@Param("userId") Long userId);

    /**
     * 删除指定的搜索历史记录
     * @param userId 用户ID
     * @param id 搜索历史记录ID
     * @return 删除记录数
     */
    @Delete("DELETE FROM search_history WHERE user_id = #{userId} AND id = #{id}")
    int deleteByUserIdAndId(@Param("userId") Long userId, @Param("id") Long id);
}
